package com.erp.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.WindowManager;

import com.erp.Myapp;
import com.erp.util.Sputil;

import static com.erp.mclass.UnCeHandler.activity;

import androidx.appcompat.app.AppCompatActivity;

/**
 * Created by Administrator on 2016/12/31/031.
 * 作者：刘洋
 */
public abstract class BaseActivity extends AppCompatActivity {
    public String activityname="";
    public SharedPreferences.Editor editor;//sp储存器
    public SharedPreferences sp;//sp提取器
    Myapp application;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        activity=activityname;
        //        透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //        透明导航栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        application = (Myapp) getApplication();
//        application.init();
        application.addActivity(this);
        editor = Sputil.editor("erp");
        sp = Sputil.sp("erp");
//        if(sp.getBoolean("apd",false)){
//            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//强制为横屏
//        }else {
//            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
//        }
        initCreate();
    }
    //加载页面布局文件
    protected abstract int getLayoutId();
    //oncreate
    protected abstract void initCreate();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        application.removeActivity(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        activity=activityname;
    }

//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if (keyCode == 4) {
//            finish();
//            overridePendingTransition(0, R.anim.end_activity1);
//        }
//        return super.onKeyDown(keyCode, event);
//    }
}
